import {
	createStore,
	applyMiddleware
} from 'redux'

//引入JS处理类
import {
	fromJS
} from 'immutable'
import thunk from 'redux-thunk'
//异步处理插件
import createSagaMiddleware from 'redux-saga';
//import rootSaga form './common/sagas'
//日志插件
import {
	createLogger
} from 'redux-logger'
//redux 必要插件
import pormiseMiddleware from 'redux-promise'

import reducers from './reducers'
const logger = createLogger()
//const sagaMiddleware = createSagaMiddleware();
const middlewares = [
	thunk,
	pormiseMiddleware,
	//sagaMiddleware,
	logger
];
//sagaMiddleware.run(rootSaga);

function configureStore(initialState = fromJS({})) {
	const enhancer = applyMiddleware(...middlewares)
	const store = createStore(reducers(), initialState, enhancer)

	if (module.hot) {
		module.hot.accept(() => {
			store.replaceReducer(require('./reducers').default)
		})
	}
	return store
}
export default configureStore